package D150;

public class longestCommonPrefix {
    public static void main(String[] args) {
        String[] strs = {""};
        System.out.println(new longestCommonPrefix().longestCommonPrefix(strs));
    }
    public String longestCommonPrefix(String[] strs) {
        int min_length = Integer.MAX_VALUE;
        int index = 0;
        for (int i = 0; i < strs.length; i++) {
            if(strs[i].length() < min_length){
                min_length = strs[i].length();
                index = i;
            }
        }
        if(min_length == 0){
            return "";
        }
        for (int i = 0; i < min_length; i++) {
            int temp = 0;
            while (temp < strs.length - 1 && strs[temp].charAt(i) == strs[temp + 1].charAt(i)){
                temp++;
            }
            if(temp != strs.length - 1){
                return strs[0].substring(0,i);
            }
        }
        return strs[index];

    }
}
